local Tool = require("Tool")
local Rule = require("Rule")


local tool = Tool.new()
local rule = Rule.new()

--狐狸
local tbColor1 = {
	{   19,  466, 0xf7987a},
	{   27,  500, 0xee8779},
	{   34,  492, 0xde3920},
}
--青蛙
local tbColor2 = {
	{  139,  286, 0x014000},
	{  152,  292, 0x6ee525},
	{  152,  310, 0x2cab21},
	{  170,  303, 0x118b25},
}
--小鸡
local tbColor3 ={
	{   84,  306, 0xa75c0c},
	{   92,  311, 0xde5709},
	{   75,  317, 0xe5a43b},
	{   92,  297, 0xf9f730},
}
--河马
local tbColor4 = {
	{  225,  275, 0xb6d6f9},
	{  249,  255, 0x21bee2},
	{  236,  290, 0x0a52b6},
	{  255,  276, 0xb2d3f9},
}
--猫头鹰
local tbColor5 = {
	{  195,  357, 0x8c58bf},
	
	
}
--熊
local tbColor6 = {
	{  162,  334, 0x923c05},
	{  162,  324, 0xad5412},
	{  200,  321, 0xbb5f16},
	{  198,  336, 0x9f490c},
	{  179,  348, 0x833000},
}


local tbStartXY = {
	{0,210},
	{148,238},
	{60,270},
	{0,270},
}
local startXY = tbStartXY[1]
local x0 = startXY[1]
local y0 = startXY[2]
local coordinateMaps = {}


local function makeMap()
	local maps = {}
	keepScreen(true);   --打开保持屏幕，当参数为 true 时启用屏幕保持，运行到该函数时内存中的屏幕图像保持在这一时刻
	for y = 1, 9 do
		local row = {}
		table.insert(maps, row)
		table.insert(coordinateMaps, {})
		for x = 1, 9 do    
			maps[y][x] = 0
			local sx = x0+x*60
			local sy = y0+y*60
			coordinateMaps[y][x] = {sx+30, sy+30}
			local fx,fy = tool:findMultiColorInRegion2(tbColor1, {sx, sy, sx+60, sy+60} )			
			if fx then 
				maps[y][x] = 1
			end		
			local fx,fy = tool:findMultiColorInRegion2(tbColor2, {sx, sy, sx+60, sy+60} )
			if fx then 
				maps[y][x] = 2
			end
			local fx,fy = tool:findMultiColorInRegion2(tbColor3, {sx, sy, sx+60, sy+60} )
			if fx then 
				maps[y][x] = 3
			end
			local fx,fy = tool:findMultiColorInRegion2(tbColor4, {sx, sy, sx+60, sy+60} )
			if fx then 
				maps[y][x] = 4
			end
			local fx,fy = tool:findMultiColorInRegion2(tbColor5, {sx, sy, sx+60, sy+60} )
			if fx then 
				maps[y][x] = 5
			end
			local fx,fy = tool:findMultiColorInRegion2(tbColor6, {sx, sy, sx+60, sy+60} )
			if fx then 
				maps[y][x] = 6
			end	
		end
		
	end
	keepScreen(false);   --关闭保持屏幕，当参数为 false 时关闭屏幕保持，释放内存中的屏幕图像，以备下一次继续保持。
	return maps
end
local maps = makeMap()
local str = dump(maps)
tool:dialog(str)


